/*
 * Thread.h
 *
 *  Created on: Apr 6, 2011
 *      Author: alki
 */

#ifndef THREAD_H_
#define THREAD_H_

#include "Szene.h"
#include "objekte/Material.h"
#include "Exception.h"
#include <list>
#include <SDL/SDL_thread.h>
#include <SDL/SDL_mutex.h>

/**
 * Klasse Thread: kümmert sich um die Verwaltung der Threads
 */
class Thread {
public:
	Thread();
	virtual ~Thread();

	void SetSzene(Szene*szene) { this->m_szene=szene; }
	void SetFarbe(FARBE*farbe) { this->m_farbe=farbe; }

	unsigned int GetSize();
	/**
	 * Neuen Pixel, welcher berechnet werden soll hinzufügen
	 */
	void Add(unsigned int x,unsigned int y);

	bool finished();

	/**
	 * Thread-Methode
	 */
	int run();

	/**
	 * Thread beenden
	 */
	void End() { this->m_done=true; }
private:
	Szene *m_szene;
	bool m_done;

	typedef struct pt {
		unsigned int x;
		unsigned int y;
	} PT;
	list<PT> m_punkte;
	FARBE *m_farbe;

	SDL_Thread *m_thread;
	SDL_mutex *m_mutex;
};

#endif /* THREAD_H_ */
